package com.example.yuejian.yuejian.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.adapter.HomeTeacherAdapter;
import com.example.yuejian.yuejian.base.BaseFragment;
import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.bean.Masters;
import com.example.yuejian.yuejian.model.MastersModel;

import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class HomeTeacherFragment extends BaseFragment {

        private  View view;
    private RecyclerView recyclerView;

    List<Masters>  list;
    public HomeTeacherFragment() {
        // Required empty public constructor
    }
    private ModleListListener<Masters> modleListListener=new ModleListListener<Masters>() {
        @Override
        public void onResponse(List<Masters> l) {
            list=l;
            recyclerView.setAdapter(new HomeTeacherAdapter(getActivity(),list));

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_home_teacher, container, false);


        initViews();
        MastersModel mastersModel=new MastersModel();
        mastersModel.getMasterList(modleListListener);
        return view;
    }

    private void initViews()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.home_teacher_recycleview);
       // GridLayoutManager gm = new GridLayoutManager(this.getActivity(),2);
        // 网格是的list布局   2列
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        //recyclerView.setLayoutManager(gm);

    }

}
